"""
basepage.py


"""
from time import sleep

from selenium import webdriver


class BasePage:
    def __init__(self,driver=None):
        if driver:
            self.driver= driver
        else:
            self.driver=webdriver.Chrome()
            self.driver.maximize_window()
            self.driver.implicitly_wait(10)
    # 对定位方式 target 进行拆分
    def converter(self,target):
        name,value=target.split("=",1)# 对target字符串以等号进行分割, 只分割第一个=号
        return name.strip() ,value.strip()

    def element_locate(self,target): #target " xpath = \\*{=} "
        name,value=self.converter(target)
        return self.driver.find_element(name,value)

    def input(self,target,input_value): # target,文本框的定位方式, value 输入的值
        self.element_locate(target).send_keys(input_value)

    def type_button(self,target):
        self.element_locate(target).click()

    def get_text(self,target):
        return self.element_locate(target).text

    def open_index(self):
        self.driver.get("http://localhost/ranzhi/www/")

    def wait(self,n):
        sleep(n)

    def type_link(self,target):
        self.element_locate(target).click()

    def toframe(self,frame_name):
        self.driver.switch_to.frame(frame_name)

